#ifndef SEM_INCLUDED
#define SEM_INCLUDED

// 若使用异常，要确保 wait 和 signal 的匹配调用
#define LOCK(mutex) do { Sem_T *_yymutex = &(mutex); \
    Sem_wait(_yymutex);
#define END_LOCK Sem_signal(_yymutex); } while (0);

#define T Sem_T

typedef struct T {
    int count;
    void *queue;
} T;

void Sem_init(T *s, int count);
T*   Sem_new(int count);
void Sem_wait(T *s);
void Sem_signal(T *s);

#undef T

#endif

